﻿/*******************************************************************************
 * CreateTime:2022-04-04 11:37:47
 * Description: YoursLC有源低代码
*********************************************************************************/

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Think9.Controllers.Basic;
using Think9.Models;
using Think9.Services.Base;
using Think9.Services.Basic;
using Think9.Services.CodeBuild;
using Think9.Services.Flow;
using Think9.Services.Table;

namespace Think9.Controllers.CodeBuild
{
    public class Demo01VariousControlsController : BaseController
    {
        private Demo01VariousControlsService Demo01VariousControlsService = new Demo01VariousControlsService();
        private ComService ComService = new ComService();

        private readonly string self_maintbid = "tb_Demo01VariousControls";//主表编码
        private readonly string self_flowid = "fw_Demo01VariousControls";//流程编码 bi_基础信息 fw_一般录入表
        private readonly string self_tbname = "Demo01各种控件";//录入表名称

        private string split = BaseUtil.ComSplit;//字符分割 用于多选项的分割等
        private string str;

        #region list列表
        public override ActionResult Index(int? id)
        {
            string err = CheckCom.CheckedBeforeBegin(self_maintbid);//检查数据库是否建表等
            if (string.IsNullOrEmpty(err))
            {
                object param = BasicHelp.GetParamObject(CurrentUser);//系统参数可作为数据规范的条件参数
                ViewBag.SelectList = Demo01VariousControlsService.GetSelectList("list", param);//为查询条件(下拉选择)准备动态数据
                ViewBag.SearchMode = BasicHelp.GetSearchMode(self_flowid);//查看编辑模式

                base.Index(id);
                return View();
            }
            else
            {
                return Json(err);
            }
        }

        /// <summary>
        /// 操作前判断及数据处理 列表页面点击新增数据按钮触发
        /// </summary>
        /// <param name="type">类型add</param>
        /// <param name="listid"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult BeforeAdd(string type, string listid)
        {
            string err = "";
            int _listid = 0;
            try
            {
                //使用通用函数得到步骤第一步 基本信息录入表返回空
                CurrentPrcsEntity mPrcs = FlowCom.GetFistFlowStept(self_flowid);
                err = mPrcs == null ? "" : mPrcs.ERR;

                if (string.IsNullOrEmpty(err))
                {
                    //使用通用函数添加前检测 包括权限校验、录入表是否被禁用等
                    err = CheckCom.CheckedBeforeAdd(CurrentUser, mPrcs, self_flowid);
                    if (string.IsNullOrEmpty(err))
                    {
                        //添加前处理自动编号及子表数据初始化
                        _listid = Demo01VariousControlsService.BeforeAdd(ref err, CurrentUser, mPrcs, self_flowid, self_maintbid, self_tbname);

                    }
                }

                if (string.IsNullOrEmpty(err))
                {
                    string pid = mPrcs == null ? "-1" : mPrcs.PrcsId;
                    return Json(SuccessTip("", _listid.ToString(), pid));
                }
                else
                {
                    return Json(ErrorTip(err));
                }
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        /// <summary>
        /// 操作前判断及数据处理 列表页面点击编辑按钮触发
        /// </summary>
        /// <param name="type">类型edit</param>
        /// <param name="listid"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult BeforeEdit(string type, string listid)
        {
            string err = "";
            //使用通用函数得到当前流程步骤 基本信息录入表返回空
            CurrentPrcsEntity mPrcs = FlowCom.GetCurrentFlowStept(self_flowid, listid);
            err = mPrcs == null ? "" : mPrcs.ERR;

            if (string.IsNullOrEmpty(err))
            {
                //使用通用函数编辑前检测-包括权限校验、录入表是否被禁用、数据是否锁定等
                err = CheckCom.CheckedBeforeEdit(CurrentUser, mPrcs, self_flowid, listid);
            }

            if (string.IsNullOrEmpty(err))
            {
                string pid = mPrcs == null ? "-1" : mPrcs.PrcsId;
                return Json(SuccessTip("", listid, pid));
            }
            else
            {
                return Json(ErrorTip(err));
            }
        }

        /// <summary>
        /// 数据查看 列表页面点击查看按钮触发
        /// </summary>
        /// <param name="listid"></param>
        /// <returns></returns>
        [HttpGet]
        public  ActionResult Detail(string listid)
        {
            ViewBag.listid = listid;

            return View();
        }

        /// <summary>
        /// 数据删除 列表页面点击删除按钮触发
        /// </summary>
        /// <param name="listid"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Delete(string listid)
        {
            string err = "";

            //使用通用函数得到当前流程步骤 基本信息录入表返回空
            CurrentPrcsEntity mPrcs = FlowCom.GetCurrentFlowStept(self_flowid, listid);
            err = mPrcs == null ? "" : mPrcs.ERR;

            if (string.IsNullOrEmpty(err))
            {
                //删除前检测 包括权限校验、录入表是否被禁用、数据是否锁定等
                err = CheckCom.CheckedBeforeDel(CurrentUser, mPrcs, self_flowid, listid);
            }

            try
            {
                if (string.IsNullOrEmpty(err))
                {
                    err = Demo01VariousControlsService.DeleteByID(listid, self_flowid) ? "" : "删除失败";
                }

                if (string.IsNullOrEmpty(err))
                {
                    Record.AddRecord(CurrentUser, listid, self_flowid, "数据删除");
                    return Json(SuccessTip("删除成功"));
                }
                else
                {
                    return Json(ErrorTip(err));
                }
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        /// <summary>
        /// 数据查询 列表页面点击查询按钮触发
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pageInfo"></param>
        /// <param name="isAll">为all则显示所有</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetPageListBySearch(Demo01VariousControlsModel model, PageInfoEntity pageInfo, string isAll)
        {
            object param = BasicHelp.GetParamObject(CurrentUser);

            pageInfo.field = "listid";
            pageInfo.order = "desc";

            Demo01VariousControlsModel entity = new Demo01VariousControlsModel();
            if (string.IsNullOrEmpty(isAll))
            {
                entity = model;
            }

            long total = 0;
            //主表查询返回数据列表 查询条件可在录入表指标属性中设置
            IEnumerable<dynamic> list = Demo01VariousControlsService.GetPageListBySearch(ref total, entity, pageInfo, CurrentUser, self_flowid, self_maintbid);
            //为下拉选择、多选、单选准备动态数据源
            IEnumerable<valueTextEntity> SelectList = Demo01VariousControlsService.GetSelectList("list", param);

            //处理select、checkbox、radio等Value与Text转化
            foreach (Demo01VariousControlsModel obj in list)
            {
				//select、radio 单选
				foreach (valueTextEntity sel in SelectList.Where(x => x.ClassID == "inSingleChoice"))
				{
					if (sel.Value == obj.inSingleChoice)
					{
						obj.inSingleChoice = sel.Text;
						break;
					}
				}
				//select、radio 下拉选择
				foreach (valueTextEntity sel in SelectList.Where(x => x.ClassID == "inDropDownSelection"))
				{
					if (sel.Value == obj.inDropDownSelection)
					{
						obj.inDropDownSelection = sel.Text;
						break;
					}
				}
				//select、radio 下拉选择树
				foreach (valueTextEntity sel in SelectList.Where(x => x.ClassID == "inDropDownSelectionTree"))
				{
					if (sel.Value == obj.inDropDownSelectionTree)
					{
						obj.inDropDownSelectionTree = sel.Text;
						break;
					}
				}
				//checkbox 多选
				string sinMultipleChoice = "";
				foreach (valueTextEntity sel in SelectList.Where(x => x.ClassID == "inMultipleChoice"))
				{
					str = obj.inMultipleChoice == null ? "" : obj.inMultipleChoice.ToString(); 
					if (str.Contains(split + sel.Value + split))
					{
						sinMultipleChoice += sel.Text + " ";
					}
				}
				obj.inMultipleChoice = sinMultipleChoice;//123
            }

            if (list == null)
            {
                return Json(ErrorTip("参数错误"));
            }
            else
            {
                var result = new { code = 0, msg = "", count = total, data = list };
                return Json(result);
            }
        }
        #endregion list列表

        #region Form编辑
        /// <summary>
        /// 录入页面显示
        /// </summary>
        /// <param name="type">add或edit</param>
        /// <param name="listid"></param>
        /// <param name="pid">当前流程步骤id</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Form(string type, string listid, string pid)
        {
            int _listid = listid == null ? 0 : int.Parse(listid);
            object param = BasicHelp.GetParamObject(CurrentUser);//数据规范中的筛选条件可使用系统参数
            ViewBag.userid = CurrentUser == null ? "" : CurrentUser.Account; ;//用户id
            ViewBag.type = type;//add或edit
            ViewBag.listid = _listid;
            ViewBag.split = split;//字符分割 checkbox多选时使用
            ViewBag.fid = self_flowid;//流程编码
            ViewBag.prcid = pid;//流程步骤id
            ViewBag.prcno = FlowCom.GetFlowNoByID(self_flowid, pid);//流程步骤编码
            ViewBag.SelectList = Demo01VariousControlsService.GetSelectList(type, param);//为下拉选择、多选、单选动态数据源赋值

            Demo01VariousControlsModel model = new Demo01VariousControlsModel();
            if (type == "add")
            {
                model.ListId = _listid;
                if (_listid != 0)
                {
                    model = Demo01VariousControlsService.GetByWhereFirst("where listid=" + _listid + "");
                }
                //赋初始值--系统指标或默认值
				model.inEnterTextBox1 = CurrentUser == null ? "" : CurrentUser.Account;//系统指标当前用户登陆账号
				model.inEnterTextBox2 = CurrentUser == null ? "" : CurrentUser.RealName;//系统指标当前用户真实姓名
            }
            else
            {
                model = Demo01VariousControlsService.GetByWhereFirst("where listid=" + _listid + "");
            }

            if (model != null)
            {
                return View(model);
            }
            else
            {
                return Json("数据不存在");
            }
        }

        /// <summary>
        /// 下拉选择或者弹出选择后调用 完成数据读取功能--可在录入表管理/数据读取中自定义
        /// </summary>
        /// <param name="controlslist">页面控件id与text</param>
        /// <param name="gridlist">子表数据列表 无子表时为空</param>
        /// <param name="id"></param>
        /// <param name="tbid">主表id</param>
        /// <param name="indexid">下拉或者弹出选择(触发控件)对应指标id</param>
        /// <param name="value">下拉或者弹出选择(触发控件)对应控件Value</param>
        /// <returns>返回list交由前台解析</returns>
        [HttpPost]
        public ActionResult AfterControlSelect(IEnumerable<ControlEntity> controlslist, IEnumerable<GridListEntity> gridlist, string id, string tbid, string indexid, string value)
        {
            try
            {
                List<ControlEntity> list = new List<ControlEntity>();

                return Json(SuccessTip("", list, ""));
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        /// <summary>
        /// 数据保存  Form页面点击保存按钮触发
        /// </summary>
        /// <param name="model"></param>
        /// <param name="gridlist">子表数据 无子表时为空</param>
        /// <param name="listid">listid=0表示增加</param>
        /// <param name="prcno">流程步骤编码</param>
        /// <param name="type">add或edit</param>
        /// <param name="att">附件id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SaveData(Demo01VariousControlsModel model, IEnumerable<GridListEntity> gridlist, int listid, string prcno, string type, string att)
        {
            string err = "";
			model.inMultipleChoice = model.inMultipleChoice_Exa;//处理复选框
			model.inPicture = model.inPicture_Exa;//处理图片
            try
            {
                //编辑
                if (listid != 0)
                {
                    err = this.Edit(model, gridlist, listid, prcno);
                }
                else
                {
                    listid = this.Add(ref err, prcno, model);

                }

                if (string.IsNullOrEmpty(err) && type == "add")
                {
                    AttachmentService.UpdateAttachmentId(listid, self_flowid, att);//防止listid=0添加了附件
                }

                if (string.IsNullOrEmpty(err))
                {
                    err = Demo01VariousControlsService.AfterEdit(listid.ToString(), self_flowid, FlowCom.GetFlowIDByNo(self_flowid, prcno), CurrentUser);//编辑后数据处理

                    if (string.IsNullOrEmpty(err))
                    {
                        return Json(SuccessTip("操作成功"));
                    }
                    else
                    {
                        return Json(ErrorTip("AfterEdit函数出现错误：" + err));
                    }
                }
                else
                {
                    return Json(ErrorTip("操作失败！" + err));
                }
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        /// <summary>
        /// 转交下一步  Form页面点击转交按钮触发
        /// </summary>
        /// <param name="model"></param>
        /// <param name="gridlist">子表数据列表 无子表时为空</param>
        /// <param name="listid">listid=0表示增加</param>
        /// <param name="prcno">流程步骤编码</param>
        /// <param name="type">add或edit</param>
        /// <param name="att">附件id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult NextStep(Demo01VariousControlsModel model, IEnumerable<GridListEntity> gridlist, int listid, string prcno, string type, string att)
        {
            string err = "";
			model.inMultipleChoice = model.inMultipleChoice_Exa;//处理复选框
			model.inPicture = model.inPicture_Exa;//处理图片
            try
            {
                //编辑
                if (listid != 0)
                {
                    err = this.Edit(model, gridlist, listid, prcno);
                }
                else
                {
                    listid = this.Add(ref err, prcno, model);

                }

                if (string.IsNullOrEmpty(err) && type == "add")
                {
                    AttachmentService.UpdateAttachmentId(listid, self_flowid, att);//防止listid=0添加了附件
                }

                if (string.IsNullOrEmpty(err))
                {
                    err = Demo01VariousControlsService.AfterEdit(listid.ToString(), self_flowid, FlowCom.GetFlowIDByNo(self_flowid, prcno), CurrentUser);//编辑后数据处理

                    if (string.IsNullOrEmpty(err))
                    {
                        if (self_flowid.StartsWith("bi_"))
                        {
                          return Json(ErrorTip("数据保存成功，基本信息表不能被转交"));
                        }
                        else
                        {
                          return Json(SuccessTip("", listid.ToString()));
                        }
                    }
                    else
                    {
                        return Json(ErrorTip("AfterEdit函数出现错误：" + err));
                    }
                }
                else
                {
                    return Json(ErrorTip(err));
                }
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        /// <summary>
        /// 结束  Form页面点击结束按钮触发
        /// </summary>
        /// <param name="model"></param>
        /// <param name="gridlist">子表数据 无子表时为空</param>
        /// <param name="listid">listid=0表示增加</param>
        /// <param name="prcno">流程步骤编码</param>
        /// <param name="type">add或edit</param>
        /// <param name="att">附件id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Finish(Demo01VariousControlsModel model, IEnumerable<GridListEntity> gridlist, int listid, string prcno, string type, string att)
        {
            string err = "";
			model.inMultipleChoice = model.inMultipleChoice_Exa;//处理复选框
			model.inPicture = model.inPicture_Exa;//处理图片
            try
            {
                //编辑
                if (listid != 0)
                {
                    err = this.Edit(model, gridlist, listid, prcno);
                }
                else
                {
                    listid = this.Add(ref err, prcno, model);

                }

                if (string.IsNullOrEmpty(err) && type == "add")
                {
                    AttachmentService.UpdateAttachmentId(listid, self_flowid, att);//防止listid=0的时候添加了附件
                }

                if (string.IsNullOrEmpty(err))
                {
                    err = Demo01VariousControlsService.AfterFinish(listid.ToString(), self_flowid, FlowCom.GetFlowIDByNo(self_flowid, prcno), CurrentUser);//完成后数据处理

                    if (string.IsNullOrEmpty(err))
                    {
                        if (self_flowid.StartsWith("bi_"))
                        {
                            return Json(ErrorTip("操作成功，数据已被锁定"));
                        }
                        else
                        {
                            return Json(SuccessTip("操作成功"));
                        }
                    }
                    else
                    {
                        return Json(ErrorTip("AfterFinish函数出现错误：" + err));
                    }
                }
                else
                {
                    return Json(ErrorTip("操作失败！" + err));
                }
            }
            catch (Exception ex)
            {
                return Json(ErrorTip(ex.Message));
            }
        }

        //添加主表数据
        private int Add(ref string err, string prcno, Demo01VariousControlsModel model)
        {
            int listid = 0;

            DataTable dtMain = DataTableHelp.ModelToDataTable<Demo01VariousControlsModel>(model);
            //通用函数进行主键和唯一键检测 主键和唯一键可在录入表指标属性中设置
            err = CheckCom.CheckMainTbValueBKAndUnique(listid, self_maintbid, model, dtMain);
            if (string.IsNullOrEmpty(err))
            {
                //通用函数进行主表自定义校验 可在录入表管理/录入校验中设置
                err = CheckCom.CheckMainTbValidate(dtMain, self_flowid, prcno);
                if (string.IsNullOrEmpty(err))
                {
                    if (CurrentUser != null)
                    {
						CurrentPrcsEntity mPrcs = FlowCom.GetFistFlowStept(self_flowid);
						if (string.IsNullOrEmpty(mPrcs.ERR))
						{
							//首先FlowrunList表中添加数据返回自增长的listid FlowrunList用于记录流程信息
							listid = FlowRunListService.InsertFlowrunListReturnID(ref err, self_maintbid, self_flowid, self_tbname, CurrentUser, mPrcs);
							if (string.IsNullOrEmpty(err))
							{
								model.ListId = listid;
								err = Demo01VariousControlsService.Insert(model) ? "" : "添加失败";
								if (string.IsNullOrEmpty(err))
								{
									Record.AddRecord(CurrentUser, listid.ToString(), self_flowid, "数据添加");
								}
							}
						}
                    }
                    else
                    {
                        err = "当前用户对象为空";
                    }
                }
            }

            return listid;
        }

        //编辑主表数据
        private string Edit(Demo01VariousControlsModel model, IEnumerable<GridListEntity> gridlist, int listid, string prcno)
        {
            string err = "";

            //有子表时会遍历数据并判断取数
			List<SubTable01Model> listSubTable01 = SubTable01Service.GetGridFormList(gridlist, "", listid, ref err);

            if (string.IsNullOrEmpty(err))
            {
                model.ListId = listid;

                DataTable dtMain = DataTableHelp.ModelToDataTable<Demo01VariousControlsModel>(model);
                //主键和唯一检测 主键和唯一可在录入表指标属性中设置
                err = CheckCom.CheckMainTbValueBKAndUnique(listid, self_maintbid, model, dtMain);
                if (string.IsNullOrEmpty(err))
                {
                    //自定义校验 可在录入表管理录入校验中设置
                    err = CheckCom.CheckTbValidate(dtMain, gridlist, self_flowid, prcno);
                    if (string.IsNullOrEmpty(err))
                    {
                        //子表数据编辑
						SubTable01Service SubTable01 = new SubTable01Service();
						foreach (SubTable01Model obj in listSubTable01)
						{
							SubTable01.UpdateById(obj);
						}

                        string updateFields = Demo01VariousControlsService.GetUpdateFields(prcno);//可编辑列
                        if(!string.IsNullOrEmpty(updateFields))
                        {

                            //编辑主表
                            err = Demo01VariousControlsService.UpdateByWhere("where listid=" + listid + "", updateFields, model) > 0 ? "" : "编辑失败";
                        }

                        Record.AddRecord(CurrentUser, listid.ToString(), self_flowid, "数据编辑");
                    }
                }
            }

            return err;
        }


        #endregion Form编辑

        #region 子表处理
		
		//从子表tb_SubTable01获取数据
		[HttpGet]
		public JsonResult GetDataFromSubTable01(string tbid, int listid, string from)
		{
			SubTable01Service SubTable01 = new SubTable01Service();
			var result = new { code = 0, msg = "", count = 999999, data = SubTable01.GetGridDataByListId(CurrentUser, listid, from) };
			return Json(result);
		}

        /// <summary>
        /// 子表添加一条数据 
        /// </summary>
        /// <param name="list"></param>
        /// <param name="tbid"></param>
        /// <param name="listid"></param>
        [HttpPost]
        public ActionResult AddGrid(Demo01VariousControlsModel model, IEnumerable<GridListEntity> list, string tbid, int listid)
        {
            string err = "";
            int newid = 0;
            try
            {
                newid = this.AddItem(ref err, model, list, tbid, listid);

            }
            catch (Exception ex)
            {
                err += ex.Message;
            }

            if (newid > 0 && string.IsNullOrEmpty(err))
            {
                Record.AddRecord(CurrentUser, newid.ToString(), self_flowid, "添加子表(" + tbid + ")数据");
                return Json(SuccessTip("添加成功", newid.ToString()));
            }
            else
            {
                return Json(ErrorTip("添加失败：" + err));
            }
        }

        /// <summary>
        ///子表删除一条数据 
        /// </summary>
        /// <param name="flag"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelGrid(string flag, string listid)
        {
            string tbid = "";
            string id = "";
            BasicHelp.GetTbAndIdByFlag(flag, ref tbid, ref id);//flag=#录入表编码#id#行号#

            if (!string.IsNullOrEmpty(tbid) && !string.IsNullOrEmpty(id))
            {
                if(ComService.ExecuteSql("delete from " + tbid + " where Id=" + id + "") > 0)
                {
                    Record.AddRecord(CurrentUser, listid, self_flowid, "删除子表("+ tbid + ")数据");
                    return Json(SuccessTip("删除成功"));
                }
                else
                {
                    return Json(ErrorTip("删除失败"));
                } 
            }
            else
            {
                return Json(ErrorTip("参数错误"));
            }     
        }

        
        // 子表添加一条数据
        private int AddItem(ref string err, Demo01VariousControlsModel model, IEnumerable<GridListEntity> gridlist, string tbid, int listid)
        {
            int newid = 0;

            //添加一条子表数据 可包含多个子表
			if (tbid == "tb_SubTable01")
			{
				List<SubTable01Model> mlist = SubTable01Service.GetGridFormList(gridlist, "#tb_SubTable01#0#0#", listid, ref err);
				if (err == "")
				{
					if (listid == 0)
					{
						 if (self_flowid.StartsWith("bi_"))
						{
							newid = PageCom.InsertEmptyReturnID(ref err, self_maintbid, self_flowid, self_tbname, CurrentUser, null);
						}
						else
						{
							CurrentPrcsEntity mPrcs = FlowCom.GetFistFlowStept(self_flowid);
							newid = PageCom.InsertEmptyReturnID(ref err, self_maintbid, self_flowid, self_tbname, CurrentUser, mPrcs);
						}
					}
					else
					{
						newid = listid;
					}
					if (newid > 0)
					{
						foreach (SubTable01Model sel in mlist)
						{
							sel.ListId = newid;
							SubTable01Service server = new SubTable01Service();
							
							//主键和唯一检测
							err = CheckCom.CheckGridTbValueBKAndUnique(sel.ListId, sel.TbId, sel, DataTableHelp.ModelToDataTable<SubTable01Model>(sel));
							if(string.IsNullOrEmpty(err))
							{
								server.Insert(sel);
							}
						}
					}
					else
					{
						 err = "主表插入数据错误";
					}
				}
			}

            return newid;
        }
        #endregion 子表处理

        #region 弹出处理
        /// <summary>
        /// 弹出数据选择页面
        /// </summary>
        /// <param name="tbid"></param>
        /// <param name="indexid"></param>
        /// <param name="id"></param>
        /// <param name="strv"></param>
        /// <param name="from"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult PopUpSelectValue(string tbid, string indexid, string id, string strv, string from)
        {
           object param = BasicHelp.GetParamObject(CurrentUser);

            //处理弹出页面 若无弹出页面可删除
            ViewBag.PUtbid = tbid == null ? "" : tbid;
            ViewBag.PUindexid = indexid == null ? "" : indexid;
            ViewBag.PUid = id == null ? "" : id;
            ViewBag.PUv = strv == null ? "" : strv.Replace("v","");
            ViewBag.PUfrom = from == null ? "" : from;
            ViewBag.SelectList = Demo01VariousControlsService.GetSelectList( tbid, indexid, from, param);
            return View("Grid_" + indexid);
        }

        /// <summary>
        /// 弹出页面获得数据列表
        /// </summary>
        /// <param name="pageInfo"></param>
        /// <param name="indexid"></param>
        /// <param name="list">封装查询条件</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetPopUpTablePageList(PageInfoEntity pageInfo, string indexid, string from, IEnumerable<valueTextEntity> list)
        {
            long total = 0;
            string tbname;
            string some;
            string where;
            string order;
            PopUpTableListService tblist = new PopUpTableListService();

            IEnumerable<dynamic> _list = null;

            //处理弹出页面 若无弹出页面可删除
				
			if (indexid == "inTextBoxPopup1")
			{
				tbname = "tb_Data03";
				some = "inEmployeeCode as Value,inEmployeeCode as info1,inEmployeeName as info2,inEmployeeDepartment as info3,inEmployeePosition as info4,inEntryDate as info5,inBasePay as info6,inMeritPay as info7,inPostSalary as info8";
				where = " where 1=1";
				order =" ORDER BY inEmployeeCode";
				
				//文本框 员工编码
				string _inEmployeeCode = BasicHelp.GetTextFromList(list, indexid, "inEmployeeCode").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeCode))
				{
					where += " and inEmployeeCode like @inEmployeeCode"; 
				}
				
				//文本框 员工姓名
				string _inEmployeeName = BasicHelp.GetTextFromList(list, indexid, "inEmployeeName").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeName))
				{
					where += " and inEmployeeName like @inEmployeeName"; 
				}
				
				//下拉选择或单选框 员工部门
				string _inEmployeeDepartment = BasicHelp.GetTextFromList(list, indexid, "inEmployeeDepartment").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeDepartment))
				{
					where += " and inEmployeeDepartment = @inEmployeeDepartment"; 
				}
				
				//下拉选择或单选框 员工岗位
				string _inEmployeePosition = BasicHelp.GetTextFromList(list, indexid, "inEmployeePosition").Trim();
				if (!string.IsNullOrEmpty(_inEmployeePosition))
				{
					where += " and inEmployeePosition = @inEmployeePosition"; 
				}
				
				//入职日期
				string _inEntryDate = BasicHelp.GetTextFromList(list, indexid, "inEntryDate").Trim();
				if (!string.IsNullOrEmpty(_inEntryDate))
				{
					where += " and inEntryDate >= @inEntryDate"; 
				}
				
				//入职日期
				string _inEntryDate_Exa = BasicHelp.GetTextFromList(list, indexid, "inEntryDate_Exa").Trim();
				if (!string.IsNullOrEmpty(_inEntryDate_Exa))
				{
					where += " and inEntryDate <= @inEntryDate_Exa"; 
				}
				
				//基本工资
				string _inBasePay = BasicHelp.GetTextFromList(list, indexid, "inBasePay").Trim();
				if (!string.IsNullOrEmpty(_inBasePay))
				{
					where += " and inBasePay >= @inBasePay"; 
				}
				
				//基本工资
				string _inBasePay_Exa = BasicHelp.GetTextFromList(list, indexid, "inBasePay_Exa").Trim();
				if (!string.IsNullOrEmpty(_inBasePay_Exa))
				{
					where += " and inBasePay <= @inBasePay_Exa"; 
				}
				
				//绩效工资
				string _inMeritPay = BasicHelp.GetTextFromList(list, indexid, "inMeritPay").Trim();
				if (!string.IsNullOrEmpty(_inMeritPay))
				{
					where += " and inMeritPay >= @inMeritPay"; 
				}
				
				//绩效工资
				string _inMeritPay_Exa = BasicHelp.GetTextFromList(list, indexid, "inMeritPay_Exa").Trim();
				if (!string.IsNullOrEmpty(_inMeritPay_Exa))
				{
					where += " and inMeritPay <= @inMeritPay_Exa"; 
				}
				
				//岗位工资
				string _inPostSalary = BasicHelp.GetTextFromList(list, indexid, "inPostSalary").Trim();
				if (!string.IsNullOrEmpty(_inPostSalary))
				{
					where += " and inPostSalary >= @inPostSalary"; 
				}
				
				//岗位工资
				string _inPostSalary_Exa = BasicHelp.GetTextFromList(list, indexid, "inPostSalary_Exa").Trim();
				if (!string.IsNullOrEmpty(_inPostSalary_Exa))
				{
					where += " and inPostSalary <= @inPostSalary_Exa"; 
				}
				
				//职称津贴
				string _inTitleAllowance = BasicHelp.GetTextFromList(list, indexid, "inTitleAllowance").Trim();
				if (!string.IsNullOrEmpty(_inTitleAllowance))
				{
					where += " and inTitleAllowance >= @inTitleAllowance"; 
				}
				
				//职称津贴
				string _inTitleAllowance_Exa = BasicHelp.GetTextFromList(list, indexid, "inTitleAllowance_Exa").Trim();
				if (!string.IsNullOrEmpty(_inTitleAllowance_Exa))
				{
					where += " and inTitleAllowance <= @inTitleAllowance_Exa"; 
				}
				
				//调薪时间
				string _inSalaryAdjustmentTime = BasicHelp.GetTextFromList(list, indexid, "inSalaryAdjustmentTime").Trim();
				if (!string.IsNullOrEmpty(_inSalaryAdjustmentTime))
				{
					where += " and inSalaryAdjustmentTime >= @inSalaryAdjustmentTime"; 
				}
				
				//调薪时间
				string _inSalaryAdjustmentTime_Exa = BasicHelp.GetTextFromList(list, indexid, "inSalaryAdjustmentTime_Exa").Trim();
				if (!string.IsNullOrEmpty(_inSalaryAdjustmentTime_Exa))
				{
					where += " and inSalaryAdjustmentTime <= @inSalaryAdjustmentTime_Exa"; 
				}
				
				object param = new { inEmployeeCode = string.Format("%{0}%", _inEmployeeCode),inEmployeeName = string.Format("%{0}%", _inEmployeeName),inEmployeeDepartment = _inEmployeeDepartment,inEmployeePosition = _inEmployeePosition,inEntryDate = ExtConvert.ToDateOrNull(_inEntryDate),inEntryDate_Exa = ExtConvert.ToDateOrNull(_inEntryDate_Exa),inBasePay = ExtConvert.ToDecimalOrNull(_inBasePay),inBasePay_Exa = ExtConvert.ToDecimalOrNull(_inBasePay_Exa),inMeritPay = ExtConvert.ToDecimalOrNull(_inMeritPay),inMeritPay_Exa = ExtConvert.ToDecimalOrNull(_inMeritPay_Exa),inPostSalary = ExtConvert.ToDecimalOrNull(_inPostSalary),inPostSalary_Exa = ExtConvert.ToDecimalOrNull(_inPostSalary_Exa),inTitleAllowance = ExtConvert.ToDecimalOrNull(_inTitleAllowance),inTitleAllowance_Exa = ExtConvert.ToDecimalOrNull(_inTitleAllowance_Exa),inSalaryAdjustmentTime = ExtConvert.ToDateOrNull(_inSalaryAdjustmentTime),inSalaryAdjustmentTime_Exa = ExtConvert.ToDateOrNull(_inSalaryAdjustmentTime_Exa) };
				
				 _list = tblist.GetPageList(ref total, pageInfo, some, tbname, where, order,  param);
			}
				
			if (indexid == "inTextBoxPopup2")
			{
				tbname = "tb_Data07";
				some = "inCode as Value,inCode as info1,inName as info2,inName2 as info3,inDecimal1 as info4";
				where = " where 1=1";
				order =" ORDER BY inName";
				
				//文本框 编码
				string _inCode = BasicHelp.GetTextFromList(list, indexid, "inCode").Trim();
				if (!string.IsNullOrEmpty(_inCode))
				{
					where += " and inCode like @inCode"; 
				}
				
				//文本框 名称
				string _inName = BasicHelp.GetTextFromList(list, indexid, "inName").Trim();
				if (!string.IsNullOrEmpty(_inName))
				{
					where += " and inName like @inName"; 
				}
				
				//下拉选择或单选框 名称2
				string _inName2 = BasicHelp.GetTextFromList(list, indexid, "inName2").Trim();
				if (!string.IsNullOrEmpty(_inName2))
				{
					where += " and inName2 = @inName2"; 
				}
				
				//小数1
				string _inDecimal1 = BasicHelp.GetTextFromList(list, indexid, "inDecimal1").Trim();
				if (!string.IsNullOrEmpty(_inDecimal1))
				{
					where += " and inDecimal1 >= @inDecimal1"; 
				}
				
				//小数1
				string _inDecimal1_Exa = BasicHelp.GetTextFromList(list, indexid, "inDecimal1_Exa").Trim();
				if (!string.IsNullOrEmpty(_inDecimal1_Exa))
				{
					where += " and inDecimal1 <= @inDecimal1_Exa"; 
				}
				
				object param = new { inCode = string.Format("%{0}%", _inCode),inName = string.Format("%{0}%", _inName),inName2 = _inName2,inDecimal1 = ExtConvert.ToDecimalOrNull(_inDecimal1),inDecimal1_Exa = ExtConvert.ToDecimalOrNull(_inDecimal1_Exa) };
				
				 _list = tblist.GetPageList(ref total, pageInfo, some, tbname, where, order,  param);
			}
				
			if (indexid == "SubTable01v4")
			{
				tbname = "tb_Data03";
				some = "inEmployeeCode as Value,inEmployeeCode as info1,inEmployeeName as info2,inEmployeeDepartment as info3,inEmployeePosition as info4,inEntryDate as info5,inBasePay as info6,inMeritPay as info7,inPostSalary as info8";
				where = " where 1=1";
				order =" ORDER BY inEmployeeCode";
				
				//文本框 员工编码
				string _inEmployeeCode = BasicHelp.GetTextFromList(list, indexid, "inEmployeeCode").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeCode))
				{
					where += " and inEmployeeCode like @inEmployeeCode"; 
				}
				
				//文本框 员工姓名
				string _inEmployeeName = BasicHelp.GetTextFromList(list, indexid, "inEmployeeName").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeName))
				{
					where += " and inEmployeeName like @inEmployeeName"; 
				}
				
				//下拉选择或单选框 员工部门
				string _inEmployeeDepartment = BasicHelp.GetTextFromList(list, indexid, "inEmployeeDepartment").Trim();
				if (!string.IsNullOrEmpty(_inEmployeeDepartment))
				{
					where += " and inEmployeeDepartment = @inEmployeeDepartment"; 
				}
				
				//下拉选择或单选框 员工岗位
				string _inEmployeePosition = BasicHelp.GetTextFromList(list, indexid, "inEmployeePosition").Trim();
				if (!string.IsNullOrEmpty(_inEmployeePosition))
				{
					where += " and inEmployeePosition = @inEmployeePosition"; 
				}
				
				//入职日期
				string _inEntryDate = BasicHelp.GetTextFromList(list, indexid, "inEntryDate").Trim();
				if (!string.IsNullOrEmpty(_inEntryDate))
				{
					where += " and inEntryDate >= @inEntryDate"; 
				}
				
				//入职日期
				string _inEntryDate_Exa = BasicHelp.GetTextFromList(list, indexid, "inEntryDate_Exa").Trim();
				if (!string.IsNullOrEmpty(_inEntryDate_Exa))
				{
					where += " and inEntryDate <= @inEntryDate_Exa"; 
				}
				
				//基本工资
				string _inBasePay = BasicHelp.GetTextFromList(list, indexid, "inBasePay").Trim();
				if (!string.IsNullOrEmpty(_inBasePay))
				{
					where += " and inBasePay >= @inBasePay"; 
				}
				
				//基本工资
				string _inBasePay_Exa = BasicHelp.GetTextFromList(list, indexid, "inBasePay_Exa").Trim();
				if (!string.IsNullOrEmpty(_inBasePay_Exa))
				{
					where += " and inBasePay <= @inBasePay_Exa"; 
				}
				
				//绩效工资
				string _inMeritPay = BasicHelp.GetTextFromList(list, indexid, "inMeritPay").Trim();
				if (!string.IsNullOrEmpty(_inMeritPay))
				{
					where += " and inMeritPay >= @inMeritPay"; 
				}
				
				//绩效工资
				string _inMeritPay_Exa = BasicHelp.GetTextFromList(list, indexid, "inMeritPay_Exa").Trim();
				if (!string.IsNullOrEmpty(_inMeritPay_Exa))
				{
					where += " and inMeritPay <= @inMeritPay_Exa"; 
				}
				
				//岗位工资
				string _inPostSalary = BasicHelp.GetTextFromList(list, indexid, "inPostSalary").Trim();
				if (!string.IsNullOrEmpty(_inPostSalary))
				{
					where += " and inPostSalary >= @inPostSalary"; 
				}
				
				//岗位工资
				string _inPostSalary_Exa = BasicHelp.GetTextFromList(list, indexid, "inPostSalary_Exa").Trim();
				if (!string.IsNullOrEmpty(_inPostSalary_Exa))
				{
					where += " and inPostSalary <= @inPostSalary_Exa"; 
				}
				
				//职称津贴
				string _inTitleAllowance = BasicHelp.GetTextFromList(list, indexid, "inTitleAllowance").Trim();
				if (!string.IsNullOrEmpty(_inTitleAllowance))
				{
					where += " and inTitleAllowance >= @inTitleAllowance"; 
				}
				
				//职称津贴
				string _inTitleAllowance_Exa = BasicHelp.GetTextFromList(list, indexid, "inTitleAllowance_Exa").Trim();
				if (!string.IsNullOrEmpty(_inTitleAllowance_Exa))
				{
					where += " and inTitleAllowance <= @inTitleAllowance_Exa"; 
				}
				
				//调薪时间
				string _inSalaryAdjustmentTime = BasicHelp.GetTextFromList(list, indexid, "inSalaryAdjustmentTime").Trim();
				if (!string.IsNullOrEmpty(_inSalaryAdjustmentTime))
				{
					where += " and inSalaryAdjustmentTime >= @inSalaryAdjustmentTime"; 
				}
				
				//调薪时间
				string _inSalaryAdjustmentTime_Exa = BasicHelp.GetTextFromList(list, indexid, "inSalaryAdjustmentTime_Exa").Trim();
				if (!string.IsNullOrEmpty(_inSalaryAdjustmentTime_Exa))
				{
					where += " and inSalaryAdjustmentTime <= @inSalaryAdjustmentTime_Exa"; 
				}
				
				object param = new { inEmployeeCode = string.Format("%{0}%", _inEmployeeCode),inEmployeeName = string.Format("%{0}%", _inEmployeeName),inEmployeeDepartment = _inEmployeeDepartment,inEmployeePosition = _inEmployeePosition,inEntryDate = ExtConvert.ToDateOrNull(_inEntryDate),inEntryDate_Exa = ExtConvert.ToDateOrNull(_inEntryDate_Exa),inBasePay = ExtConvert.ToDecimalOrNull(_inBasePay),inBasePay_Exa = ExtConvert.ToDecimalOrNull(_inBasePay_Exa),inMeritPay = ExtConvert.ToDecimalOrNull(_inMeritPay),inMeritPay_Exa = ExtConvert.ToDecimalOrNull(_inMeritPay_Exa),inPostSalary = ExtConvert.ToDecimalOrNull(_inPostSalary),inPostSalary_Exa = ExtConvert.ToDecimalOrNull(_inPostSalary_Exa),inTitleAllowance = ExtConvert.ToDecimalOrNull(_inTitleAllowance),inTitleAllowance_Exa = ExtConvert.ToDecimalOrNull(_inTitleAllowance_Exa),inSalaryAdjustmentTime = ExtConvert.ToDateOrNull(_inSalaryAdjustmentTime),inSalaryAdjustmentTime_Exa = ExtConvert.ToDateOrNull(_inSalaryAdjustmentTime_Exa) };
				
				 _list = tblist.GetPageList(ref total, pageInfo, some, tbname, where, order,  param);
			}
				
			if (indexid == "SubTable01v5")
			{
				tbname = "tb_Data04";
				some = "inCode as Value,inCode as info1,inName as info2";
				where = " where 1=1";
				order =" ORDER BY inCategory";
				
				object param = new {  };
				
				 _list = tblist.GetPageList(ref total, pageInfo, some, tbname, where, order,  param);
			}

            
            if (_list == null)
            {
                return Json(ErrorTip("参数错误"));
            }
            else
            {
                var result = new { code = 0, msg = "", count = total, data = _list };
                return Json(result);
            }
        }
        #endregion 弹出处理
    }
}